package com.spring.demo.webflux.demo.controller;

import com.spring.demo.webflux.demo.dao.PersonRepository;
import com.spring.demo.webflux.demo.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wangzhilong
 * @date 2021/3/18
 */
@RestController
public class MongodbController {

    @Autowired
    private PersonRepository personRepository ;


    @PostMapping("save")
    public Person save(Person person){
        return personRepository.save(person);
    }

    @GetMapping("findAll")
    public List<Person> findAll(){
        return personRepository.findAll();
    }

    @GetMapping("findid")
    public Person findid(String id){
        return personRepository.findById(id).get();
    }

    @GetMapping("findName")
    public Person findName(String name) {
        return personRepository.findByNameLike(name);
    }



}
